<template>
  <div class="common-features-container">
    <h2 class="section-title">常用功能</h2>
    
    <div class="features-grid">
      <div 
        v-for="(feature, index) in features" 
        :key="index" 
        class="feature-card"
        @click="navigateToFeature(feature)"
        :style="{ animationDelay: `${index * 0.1}s` }"
      >
        <div class="feature-icon" :style="{ backgroundColor: feature.bgColor }">
          <el-icon><component :is="feature.icon" /></el-icon>
        </div>
        <h3 class="feature-title">{{ feature.title }}</h3>
        <p class="feature-description">{{ feature.description }}</p>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue';
import { useStore } from 'vuex';
import { useRouter } from 'vue-router';
import { 
  QuestionFilled, 
  ChatLineRound, 
  DataAnalysis, 
  Calendar,
  Document,
  Collection,
  Notebook,
  Timer
} from '@element-plus/icons-vue';

const store = useStore();
const router = useRouter();

// 修改计算属性的实现方式
const features = computed(() => {
  // 如果store中有数据，则使用store中的数据
  // if (store.state.home && store.state.home.commonFeatures) {
  //   return store.state.home.commonFeatures;
  // }
  
  // 否则使用默认数据
  return [
    {
      title: "AI助手",
      description: "智能问答，解决学习难题",
      icon: "ChatLineRound",
      bgColor: "#409EFF",
      link: "/chat"
    },


    {
      title: "笔记本",
      description: "智能笔记整理与分享",
      icon: "Notebook",
      bgColor: "#9B59B6",
      link: "/notes"
    },
    {
      title: "错题本",
      description: "记录和分析错题",
      icon: "Document",
      bgColor: "#F56C6C",
      link: "/mistake-book"
    },

    {
      title: "思维导图",
      description: "可视化知识结构",
      icon: "DataAnalysis",
      bgColor: "#E6A23C",
      link: "/mind-map"
    },
    {
      title: "学习资源",
      description: "海量优质学习资源",
      icon: "Collection",
      bgColor: "#909399",
      link: "/resources"
    },
    {
      title: "学习统计",
      description: "学习数据分析与报告",
      icon: "DataAnalysis",
      bgColor: "#3498DB",
      link: "/statistics"
    },
    {
      title: "学习计划",
      description: "制定个性化学习计划",
      icon: "Calendar",
      bgColor: "#67C23A",
      link: "/learning-plan"
    },
    {
      title: "学习提醒",
      description: "定时提醒，养成好习惯",
      icon: "Timer",
      bgColor: "#1ABC9C",
      link: "/reminders"
    }
  ];
});

// 导航到功能页面
const navigateToFeature = (feature) => {
  router.push(feature.link);
};
</script>

<style lang="scss" scoped>
.common-features-container {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
  padding-bottom: 20px;
  margin: 20px 0;
  
  .section-title {
    padding: 15px;
    margin: 0;
    font-size: 18px;
    color: #303133;
    border-bottom: 1px solid #ebeef5;
  }
  
  .features-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    padding: 20px;
    
    @media (max-width: 1200px) {
      grid-template-columns: repeat(3, 1fr);
    }
    
    @media (max-width: 768px) {
      grid-template-columns: repeat(2, 1fr);
    }
    
    .feature-card {
      background-color: #f9f9f9;
      border-radius: 8px;
      padding: 20px;
      text-align: center;
      cursor: pointer;
      transition: transform 0.3s, box-shadow 0.3s;
      animation: fadeIn 0.5s ease-out forwards;
      opacity: 0;
      
      &:hover {
        transform: translateY(-5px);
        box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
      }
      
      .feature-icon {
        width: 60px;
        height: 60px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0 auto 15px;
        color: #fff;
        font-size: 24px;
      }
      
      .feature-title {
        margin: 0 0 10px;
        font-size: 16px;
        color: #303133;
      }
      
      .feature-description {
        margin: 0;
        color: #606266;
        font-size: 14px;
        line-height: 1.5;
      }
    }
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
</style> 